package com.ericsson.eritask.service.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Service;

import com.ericsson.eritask.domain.User;
import com.ericsson.eritask.dto.MyTaskDTO;
import com.ericsson.eritask.service.UserService;

@Service
public class TaskAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

	@Autowired
	UserService userService;
	@Override
	public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
			Authentication authentication) throws IOException, ServletException {
		Authentication auth= SecurityContextHolder.getContext().getAuthentication();

		System.out.format("Name of the user is %s", auth.getName());
		User user = userService.findByName(auth.getName());
		request.getSession().setAttribute("user_signum", user.getSignum());
		response.sendRedirect("/eritasks/validateUser");
	}

}
